﻿namespace ExamV5.StudyInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmMyStudyLog : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        private int int_0 = 0;
        protected Label labID;
        private PublicFun publicFun_0 = new PublicFun();
        protected RadioButtonList RBLFlag;
        private string string_0 = "B";
        protected HtmlInputHidden txtStudyLog;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            if (this.txtStudyLog.Value.Trim() == "")
            {
                base.Response.Write("<script>alert('请输入笔记内容！')</script>");
            }
            else
            {
                SqlConnection connection;
                SqlCommand command;
                string cmdText = "";
                if (!(this.labID.Text.Trim() == "0"))
                {
                    cmdText = string.Concat(new object[] { "Update StudyLogInfo set LogInfo=@LogInfo,Flag=@Flag where UserCode='", this.httpCookie_0.Value, "' and RubricType='", this.string_0, "' and RubricID='", this.int_0, "' and ID=", this.publicFun_0.CheckString(this.labID.Text) });
                    connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                    connection.Open();
                    command = new SqlCommand(cmdText, connection);
                    command.Parameters.Add("@LogInfo", SqlDbType.Text).Value = this.txtStudyLog.Value;
                    command.Parameters.Add("@Flag", SqlDbType.Char, 1).Value = this.RBLFlag.SelectedItem.Value;
                    command.ExecuteNonQuery();
                    command.Dispose();
                    connection.Close();
                    connection.Dispose();
                }
                else
                {
                    cmdText = "insert into StudyLogInfo(RubricID,LogInfo,UserCode,Flag,RubricType) values(@RubricID,@LogInfo,@UserCode,@Flag,@RubricType)";
                    connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                    connection.Open();
                    command = new SqlCommand(cmdText, connection);
                    command.Parameters.Add("@RubricID", SqlDbType.Int).Value = this.int_0;
                    command.Parameters.Add("@LogInfo", SqlDbType.Text).Value = this.txtStudyLog.Value;
                    command.Parameters.Add("@UserCode", SqlDbType.VarChar, 50).Value = this.httpCookie_0.Value;
                    command.Parameters.Add("@Flag", SqlDbType.Char, 1).Value = this.RBLFlag.SelectedItem.Value;
                    command.Parameters.Add("@RubricType", SqlDbType.Char, 1).Value = this.string_0;
                    command.ExecuteNonQuery();
                    command.Dispose();
                    connection.Close();
                    connection.Dispose();
                }
                base.Response.Write("<script>alert('笔记提交操作成功！');window.close();</script>");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_4 = new HttpCookie("ExamUserSex");
            this.httpCookie_4 = base.Request.Cookies["ExamUserSex"];
            this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
            this.string_0 = this.publicFun_0.CheckString(base.Request["Flag"].ToString());
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
                this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        if (this.int_0 != 0)
                        {
                            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                            connection.Open();
                            SqlCommand command = new SqlCommand(string.Concat(new object[] { "select ID,LogInfo,Flag from StudyLogInfo where UserCode='", this.httpCookie_0.Value, "' and RubricType='", this.string_0, "' and  RubricID=", this.int_0 }), connection);
                            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                            if (reader.Read())
                            {
                                this.txtStudyLog.Value = reader["LogInfo"].ToString();
                                this.RBLFlag.SelectedIndex = -1;
                                this.RBLFlag.Items.FindByValue(reader["Flag"].ToString()).Selected = true;
                                this.labID.Text = reader["ID"].ToString();
                            }
                            reader.Close();
                            command.Dispose();
                            connection.Close();
                            connection.Dispose();
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请与管理员联系！')</script>");
                    }
                }
            }
        }
    }
}

